00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _DEPACKET_HPP
00029 #define _DEPACKET_HPP
00030
00031 #ifndef _DENET_HPP
00032 #include "deNet.hpp"
00033 #endif
00034
00035 #ifndef _DENETMSG_HPP
00036 #include "deNetMsg.hpp"
00037 #endif
00038
00039 class DENET_API dePacket
00040 {
00041 public:
00042
00043
00044 enum eFlag
00045 {
00046 PACKET_SEND_RECP_CONFIRMATION = 0x01,
00047 PACKET_FRAGMENT_BEGIN = 0x02,
00048 PACKET_FRAGMENT_END = 0x04,
00049 PACKET_FRAGMENT = 0x06,
00050 };
00051
00052
00053 struct PacketHeader
00054 {
00055 hNetUser Recipient;
00056 BYTE Type;
00057 BYTE Flags;
00058
00059 union
00060 {
00061 struct
00062 {
00063 hNetUser Sender;
00064 WORD LocalID;
00065 };
00066
00067 DWORD ID;
00068 };
00069 WORD NetMsgID;
00070 WORD SubID;
00071 DWORD Size;
00072 DWORD TotalSize;
00073 };
00074
00075 dePacket(void);
00076 dePacket( const BYTE * pData, DWORD dwFlags = NULL );
00077 dePacket( const PacketHeader& pHeader, const void * m_Data, DWORD dwFlags = NULL );
00078 virtual ~dePacket(void);
00079
00080 bool NeedRecvConfirmation(void) const { return m_Header.Flags & dePacket::PACKET_SEND_RECP_CONFIRMATION != 0; }
00081 bool IsFragmented(void) const { return m_Header.Flags & dePacket::PACKET_FRAGMENT != 0; }
00082 BYTE * GetData(void) const { return m_Data; }
00083 const PacketHeader& GetHeader(void) const { return m_Header; }
00084
00085 static dePacket * SortPackets( dePacket * pPackets, int iNumPackets );
00086 static dePacket * ConsolidatePackets( const dePacket * pPackets, int iNumPackets );
00087
00088 protected:
00089
00090 BYTE * m_Data;
00091 PacketHeader m_Header;
00092
00093 public:
00094
00095 static int ComparePacket( const void * l, const void * r );
00096 friend bool operator != ( const dePacket& l, const dePacket& r ) { return ( l.m_Header.ID != r.m_Header.ID ); }
00097 friend bool operator == ( const dePacket& l, const dePacket& r ) { return ( l.m_Header.ID == r.m_Header.ID ); }
00098 friend bool operator > ( const dePacket& l, const dePacket& r ) { if( l.m_Header.ID == r.m_Header.ID ) return l.m_Header.SubID > r.m_Header.SubID; else return l.m_Header.ID > r.m_Header.ID; }
00099 friend bool operator < ( const dePacket& l, const dePacket& r ) { if( l.m_Header.ID == r.m_Header.ID ) return l.m_Header.SubID < r.m_Header.SubID; else return l.m_Header.ID < r.m_Header.ID; }
00100 dePacket& operator = ( const dePacket& r );
00101 };
00102
00103 #endif